home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows5 / xwinc100.zip / CONTRIB-.00 / CONTRIB- / contrib / examples / PEX / pickplus.c < prev    next >
C/C++ Source or Header  |  1991-02-16  |  8KB  |  291 lines

  1. /* $XConsortium: pickplus.c,v 5.1 91/02/16 09:32:43 rws Exp $ */
  2.  
  3. /***********************************************************
  4. Copyright (c) 1991 by Sun Microsystems, Inc. and the X Consortium.
  5.  
  6.                         All Rights Reserved
  7.  
  8. Permission to use, copy, modify, and distribute this software and its 
  9. documentation for any purpose and without fee is hereby granted, 
  10. provided that the above copyright notice appear in all copies and that
  11. both that copyright notice and this permission notice appear in 
  12. supporting documentation, and that the names of Sun Microsystems,
  13. the X Consortium, and MIT not be used in advertising or publicity 
  14. pertaining to distribution of the software without specific, written 
  15. prior permission.  
  16.  
  17. SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
  18. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT 
  19. SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
  20. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23. SOFTWARE.
  24.  
  25. ******************************************************************/
  26.  
  27. /**
  28. ***  Sample pick program to test picking of FillAreas, Nurb Curve, QuadMesh
  29. ***  and Triangle Strips.
  30. ***/
  31.  
  32. #include "phigs/phigs.h"
  33.  
  34. #define ROWS    20
  35. #define COLUMNS 20
  36.  
  37. static Plimit viewport = {100.0,500.0,100.0,500.0};
  38. static Ppoint points[5] = {0.01,0.01, 0.01,0.99, 0.99,0.99, 0.99,0.01, 0.01,0.01};
  39. static Ppoint_list   line;
  40. static   Plimit            ea={100.0, 500.0, 100.0, 500.0 };
  41.  
  42. /* Fill Area Data */
  43. static Ppoint3 farea[] = { 0.01,0.01,0.0, 0.8,0.8,0.0, 0.7,0.01,0.0};
  44. static Ppoint_list3 fset = {3,farea};
  45. static Pview_rep3 viewrep = {
  46.        {1.0,0.0,0.0,0.0},
  47.        {0.0,1.0,0.0,0.0},
  48.        {0.0,0.0,1.0,0.0},
  49.        {0.0,0.0,0.0,1.0},
  50.  
  51.        {1.0,0.0,0.0,0.0},
  52.        {0.0,1.0,0.0,0.0},
  53.        {0.0,0.0,1.0,0.0},
  54.        {0.0,0.0,0.0,1.0},
  55.  
  56.        {0.0,0.5, 0.0,1.0, 0.0,1.0},
  57.        PIND_CLIP,
  58.        PIND_CLIP,
  59.        PIND_CLIP
  60. };
  61. static Plimit win = {0.0,0.5,0.0,1.0};
  62. static Plimit3 vport = {0.0,0.5, 0.0,1.0, 0.0,1.0};
  63. static Pview_map3 viewmap;
  64. static Ppoint3 prp = {0.0,0.0,20.0};
  65.  
  66. /* Quad Mesh Data */
  67. static Pint_size    dim={COLUMNS,ROWS};
  68.         Pfacet_vdata_arr3 vdata;
  69.         Pfacet_data_arr3 fdata;
  70.         Ppoint3 *pts;
  71.         Ppoint3 *ptr;
  72.  
  73.         Pcoval *colarr;
  74.         Pcoval *color;
  75.  
  76. /* Tri Strip Data */
  77. static Ppoint3 pts1[] = {0.3,0.6,0.0, 0.5,0.5,0.5, 0.7,0.6,0.0, 0.7,0.4,0.0};
  78. static Ppoint3 pts2[] = {0.3,0.6,0.0, 0.5,0.5,0.5, 0.3,0.4,0.0, 0.7,0.4,0.0};
  79.  
  80.         Pint            err;
  81.  
  82.         Pfacet_vdata_arr3 vdata1;
  83.         Pfacet_vdata_arr3 vdata2;
  84.  
  85.     int i,j;
  86.  
  87. /* Nurb Curve Data */
  88.     Pint         order = 4;
  89.     Pfloat_list     knots;
  90. static int     numknots = 20;
  91. static Pfloat     kpts[] = {  1.0,  2.0,  3.0,  4.0,  5.0, 
  92.                 6.0,  7.0,  8.0,  9.0, 10.0,
  93.                11.0, 12.0, 13.0, 14.0, 15.0,
  94.                16.0, 17.0, 18.0, 19.0, 20.0 };
  95.     Prational     rationality = PNON_RATIONAL;
  96.     Ppoint_list34    cpoints;
  97. static Ppoint3     cpts[] = {
  98.               0.05,0.7,0.0, 
  99.               0.10,0.9,0.0,
  100.               0.15,0.5,0.0,
  101.               0.20,0.9,0.0,
  102.               0.25,0.5,0.0,
  103.               0.30,0.9,0.0,
  104.               0.35,0.5,0.0,
  105.               0.40,0.9,0.0,
  106.               0.45,0.7,0.0,
  107.              };
  108.     Pfloat        min = 5.0,
  109.             max = 9.0;
  110.  
  111.     Pint        curve_approx_type
  112.                 = PCURV_CONSTANT_PARAMETRIC_BETWEEN_KNOTS;
  113.     Pfloat        curve_approx_tolerance = 10.0;
  114.  
  115. main( argc, argv )
  116.     int        argc;
  117.     char    *argv[];
  118. {
  119.     Pin_status        status;
  120.     Pint        pet, err, names[5];
  121.     Ppick_data          drec;   
  122.     Ppick_path        path;
  123.     Ppick_path_elem     path_els[2];  
  124.     Pfilter        filt;
  125.     int                 i;
  126.  
  127.     /* Set up line */
  128.  
  129.     line.num_points = 5;
  130.     line.points = &points[0];
  131.  
  132.     /* Initialize the curve data */
  133.  
  134.     cpoints.num_points = 9;
  135.     cpoints.points.point3d = cpts;
  136.  
  137.     knots.num_floats = cpoints.num_points + order;
  138.     knots.floats = kpts;
  139.  
  140.     /* Set up Quad Mesh */
  141.  
  142.     ptr = pts = (Ppoint3 *)malloc(ROWS*COLUMNS*sizeof(Ppoint3));
  143.     color = colarr = (Pcoval *)malloc(ROWS*COLUMNS*sizeof(Pcoval));
  144.  
  145.     for (i = 0; i < ROWS; i++) {
  146.     for (j = 0; j < COLUMNS; j++) {
  147.         ptr->x     = 0.5 + j * (0.5/(COLUMNS));
  148.         ptr->y     = 0.5 + i * (0.5/(ROWS));
  149.         (ptr++)->z = 0.0;
  150.     }
  151.     }
  152.  
  153.     for (i = 0; i < (ROWS-1); i++) {
  154.     for (j = 0; j < (COLUMNS-1); j++) {
  155.         color->direct.rgb.red        = j * (1.0/(COLUMNS-2));
  156.         color->direct.rgb.green      = i * (1.0/(ROWS-2));
  157.         (color++)->direct.rgb.blue  = 0.0;
  158.     }
  159.     }
  160.  
  161.     fdata.colrs = colarr;
  162.     vdata.points = pts;
  163.  
  164.     /* Set up Tri Strip */
  165.  
  166.     vdata1.points = pts1;
  167.     vdata2.points = pts2;
  168.  
  169.     /* Initialize PHIGS and start up */
  170.  
  171.     popen_phigs( (char *)NULL, PDEF_MEM_SIZE );
  172.  
  173.     /* Set up the view */
  174.  
  175.     viewmap.win = win;
  176.     viewmap.vp = vport;
  177.     viewmap.proj_type = PTYPE_PERSPECT;
  178.     viewmap.proj_ref_point = prp;
  179.     viewmap.view_plane = 0.0;
  180.     viewmap.front_plane = 1.0;
  181.     viewmap.back_plane = 0.0;
  182.     peval_view_map_matrix3(&viewmap,&err,viewrep.map_matrix);
  183.     if (err) printf("error %d in evalviewmappingmatrix3",err);
  184.  
  185.     /* Build the CSS */
  186.  
  187.     popen_struct( 1 );
  188.     plabel( 3 );
  189.     pset_pick_id( 4 );
  190.     pexec_struct( 2 );
  191.     pclose_struct();
  192.     popen_struct( 2 );
  193.     names[0] = 1;
  194.     filt.incl_set.num_ints = 1;
  195.     filt.incl_set.ints = names;
  196.     padd_names_set( &filt.incl_set );
  197.         pset_line_colr_ind(1);      /* Set the line color to white */
  198.     ppolyline( &line );         /* #3 */
  199.  
  200.         pset_int_style(PSTYLE_SOLID);
  201.         pset_int_colr_ind(2);
  202.         pset_edge_flag(PEDGE_ON);
  203.         pset_edge_colr_ind(3);
  204.         pquad_mesh3_data(PFACET_COLOUR,PVERT_COORD,PMODEL_RGB,&dim,&fdata,&vdata);                                 /* #8 */
  205.         pset_int_colr_ind(4);
  206.         pset_edgewidth (2.0);
  207.         pset_edge_colr_ind(5);
  208.         pset_view_ind(1);
  209.         pfill_area_set3(1,&fset);   /* #13 */
  210.  
  211.         pset_view_ind(0);
  212.         pset_int_colr_ind(6);
  213.         pset_edge_colr_ind(7);
  214.         pset_int_shad_meth(PSD_NONE);
  215.         pset_refl_eqn(PREFL_AMBIENT);
  216.         ptri_strip3_data(PFACET_NONE,PVERT_COORD,PMODEL_RGB,4,NULL,&vdata1);
  217.                                     /* #19 */
  218.         ptri_strip3_data(PFACET_NONE,PVERT_COORD,PMODEL_RGB,4,NULL,&vdata2);
  219.                                     /* #20 */
  220.  
  221.         pset_line_colr_ind(5);      /* Set the curve color to yellow */
  222.     pset_curve_approx(curve_approx_type, curve_approx_tolerance);
  223.     pnuni_bsp_curv(order, &knots, rationality, &cpoints, min, max);
  224.                                     /* #23 */
  225.     pclose_struct();
  226.  
  227.     /* Open a X-tool workstation */
  228.  
  229.     popen_ws( 1, (char *)NULL, phigs_ws_type_x_tool );
  230.     pset_ws_vp( 1, &viewport );
  231.     pset_view_rep3(1,1,&viewrep);
  232.  
  233.     /* Post the structure */
  234.  
  235.     ppost_struct( 1, 1, 1.0 );
  236.  
  237.     /* Make everything detectable */
  238.  
  239.     if (argc == 1) {
  240.     names[0] = 1;
  241.     filt.incl_set.num_ints = 1;
  242.     filt.incl_set.ints = names;
  243.     filt.excl_set.num_ints = 0;
  244.     filt.excl_set.ints = (Pint *)NULL;
  245.     pset_pick_filter( 1, 1, &filt );
  246.  
  247.     /* Initialize and enable the Pick device */
  248.  
  249.     path.depth = 0;
  250.     path.path_list = path_els;
  251.     pet =1;
  252.     pinit_pick( 1, 1, PIN_STATUS_NONE, &path, pet, &ea, &drec, PORDER_TOP_FIRST );
  253.     pset_pick_mode( 1, 1, POP_REQ, PSWITCH_NO_ECHO );
  254.  
  255.     /* Set up a Picking Loop */
  256.  
  257.     printf ("Type '^c' to quit; else keep picking:\n");
  258.     while (1) {
  259.  
  260.         /* Request Pick */
  261.  
  262.         status = PIN_STATUS_NONE;
  263.         preq_pick(1, 1, 2, &status, &path);
  264.  
  265.         /* Check if anything got picked; if so, print it */
  266.  
  267.         if (status == PIN_STATUS_OK) {
  268.         printf ("Path depth = %d\n", path.depth);
  269.         for (i=0; i<path.depth; i++) {
  270.             printf ("Structure ID = %d\n", path.path_list[i].struct_id);
  271.             printf ("Pick ID = %d\n", path.path_list[i].pick_id);
  272.             printf ("Element Number = %d\n", path.path_list[i].elem_pos);
  273.         }
  274.         printf ("\n");
  275.         }
  276.         else {
  277.         printf ("Nothing detected ! !\n");
  278.         printf ("\n");
  279.         }
  280.     }
  281.     }
  282.  
  283.     /* Close up */
  284.  
  285.     pclose_ws( 1 );
  286.     pclose_phigs();
  287. }
  288.  
  289.  
  290.  
  291.